package battleship;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class HighScoresServlet extends HttpServlet {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            
//        System.out.println("starting HighScoresServlet");
		Gson gson = new Gson();
//        String tere = gson.toJson(new int[] {1,1,2});
//        List<UserWinLoseInformation> thing = Databasetest.getScores();
//        String tere = gson.toJson(thing);
		String tere = gson.toJson(Databasetest.getScores());

//        System.out.println("HighScoresServlet: returning " + tere);
        response.setContentType("text/plain");
        try {
    	PrintWriter out = response.getWriter();
        System.out.println("temp 2");
		out.write(tere);
//        out.write("helloooooo");
        out.close();
        } catch (Exception e) {
            System.out.println("eeeexxxxxx");
        }
//        out.close();
        System.out.println("finished HighScoresServlet");
    }
}
